<template>
    <div>
        <div class="page-title">添加管理</div>
        <el-form ref="form" :model="form" label-width="100px">
            <el-form-item label="管理账号.">
                <el-input ref="username" v-model="form.username" placeholder="请输入管理账号"></el-input>
            </el-form-item>

            <el-form-item label="管理密码.">
                <el-input ref="password" v-model="form.password" placeholder="请输入管理密码" show-password></el-input>
            </el-form-item>

            <el-form-item label="管理昵称.">
                <el-input ref="nickname" v-model="form.nickname" placeholder="请输入管理昵称"></el-input>
            </el-form-item>

            <el-form-item label="管理状态.">
                <el-switch v-model="form.status" active-color="#f8c15c"></el-switch>
            </el-form-item>

            <el-form-item>
                <el-button type="success" icon="el-icon-check" @click="submit">添加</el-button>
                <el-button icon="el-icon-close" @click="cancel">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import {
        post
    } from '@/network/request'

    export default {
        name: 'AddManager',
        data() {
            return {
                form: {
                    cid: sessionStorage.getItem('cid'),
                    username: '',
                    password: '',
                    nickname: '',
                    status: false
                }
            }
        },
        mounted() {
            this.form.status = true
        },
        methods: {
            // 提交
            submit() {
                if (this.form.username == '') {
                    this.$notify.info({
                        title: '系统提示',
                        message: '请输入管理账号',
                        offset: 70
                    })
                    this.$refs['username'].focus()
                    return false
                }

                if (this.form.password == '') {
                    this.$notify.info({
                        title: '系统提示',
                        message: '请输入管理密码',
                        offset: 70
                    })
                    this.$refs['password'].focus()
                    return false
                }

                if (this.form.nickname == '') {
                    this.$notify.info({
                        title: '系统提示',
                        message: '请输入管理昵称',
                        offset: 70
                    })
                    this.$refs['nickname'].focus()
                    return false
                }

                post('/addManager', this.form).then(res => {
                    const result = res.data
                    if (result.code == 200) {
                        this.$notify.success({
                            title: '系统提示',
                            message: '管理添加成功',
                            offset: 70
                        })
                        this.$router.push('/manager')
                    }
                }).catch()
            },
            // 取消
            cancel() {
                this.$router.push('/manager')
            }
        }
    }
</script>

<style>
</style>